#pragma strict
//////////////////////////////////////////////////////
///GUI 助手
//////////////////////////////////////////////////////
partial class GUIHelper{
	/** 是否 按下左键.OnGUI调用 */
	static function IsClick():boolean{
		return Event.current.button == 0;
	}
	/** 是否 按着修饰键.OnGUI调用
		if(GUIHelper.IsMultiKey(Keys.CtrlShiftAlt(KeyCode.A))){
			Debug.Log("press ctrl+shift+alt+A");
		}
	*/
	static function IsMultiKey(keys:String):boolean{
		return Event.current == Event.KeyboardEvent(keys);
	}
	
	//定位到屏幕中央.
	static function ScreenCenter(rect:Rect):Rect{
		rect.x = (Screen.width - rect.width) * 0.5;
		rect.y = (Screen.height - rect.height) * 0.5;
		return rect;
	}
	//定位到屏幕的右下角.
	static function ScreenRightBottom(rect:Rect):Rect{
		rect.x = (Screen.width - rect.width);
		rect.y = (Screen.height - rect.height);
		return rect;
	}
	//定位到屏幕的右上角.
	static function ScreenRightTop(rect:Rect):Rect{
		rect.x = (Screen.width - rect.width);
		rect.y = 0;
		return rect;
	}
	//定位到屏幕右侧 中间.
	static function ScreenRightCenter(rect:Rect):Rect{
		rect.x = Screen.width - rect.width;
		rect.y = (Screen.height - rect.height) * 0.5;
		return rect;
	}

	/** 字符串转换为数字格式 */
	static function Number(str:String):String{
		if(String.IsNullOrEmpty(str))
			return "0";
		return Regex.Replace(str,"[^0-9]","");
	}
	/** 在rect范围内.绘制 一个进度条. OnGUI方法调用.
	@param rect :Rect
	@param percentage [0,100]
	*/
	static function DrawProgress(rect:Rect,percentage:int){
		percentage = Mathf.Clamp(percentage,4,100);
		var offset:int = 4;
		//背景
		GUI.Box(rect,"");
		//进度
		var innerRect:Rect = rect;
			innerRect.width = (percentage * 0.01) * rect.width;
			innerRect.height -= offset;
			innerRect.y += offset * 0.5;
			innerRect.width -= offset;
			innerRect.x += offset * 0.5;
		GUI.Box(innerRect,"");
		//值
		var textRect:Rect = Rect(0,0,40,20);
			textRect.x = rect.x + (rect.width - textRect.width) * 0.5;
			textRect.y = innerRect.y + (innerRect.height - textRect.height) * 0.5;
		GUI.Label(textRect,percentage+"%");
	}

	
}